﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Azure.TableQuery.Core;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.CodeDom.Compiler;

namespace Azure.TableQuery.Tests
{
    [TestClass]
    public class QueryCompilerFixture : BaseTest
    {
        GenericEntity entity;
        public QueryCompilerFixture()
            : base()
        {
            var tableClient = new CloudTableClient(@"http://ipv4.fiddler:10002/devstoreaccount1",
                account.Credentials);

            var context = new GenericTableContext(tableClient.BaseUri.ToString(), account.Credentials);
            entity = context.GetFirstOrDefault("TestEntity");
        }
        
        [TestMethod]
        public void Compile()
        {
            string queryText = "from te in TestEntity where te.Name == \"something\" select te";
            var compiler = new QueryCompiler(entity, queryText);

            var results = compiler.Compile();
            foreach (CompilerError error in results.Errors)
            {
                Console.WriteLine(error.FileName);
                Console.WriteLine(error.ErrorText);
            }

            Assert.IsTrue(results.Errors.Count == 0);
        }
    }
}
